def prost(b):
    for i in range(2, b):
        if b%i == 0:
            return False
    return 1       
a=input()
b=0
for l in range(0,4):
    for i in range(4,0,-1):
        if i>l:
            if prost(int(a[l:i]))==1:
                if int (a[l:i])>b:
                    b=int(a[l:i])
print(b)
